

package com.feijia.aijingjingus;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import github.hellocsl.cursorwheel.CursorWheelLayout;
import github.hellocsl.cursorwheel.CursorWheelLayout.CycleWheelAdapter;

/**
 * Created by feiga on 2017/10/16.
 */

public class SimpleCycleWheelAdapter extends CycleWheelAdapter {
    static SimpleDateFormat format = new SimpleDateFormat("E");
    static SimpleDateFormat formatLong = new SimpleDateFormat("yyyy-MM-dd");
    public List<WheelItemData> data;
    private LayoutInflater inflater;
    //public static View ViewWithAni;
    private static AnimatorSet set;
    CursorWheelLayout mParent;

    public SimpleCycleWheelAdapter(AppCompatActivity activity, List<WheelItemData> data, CursorWheelLayout parent) {
        this.data = data;
        mParent = parent;
        inflater = LayoutInflater.from(activity);

    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public View getView(View parent, int position) {
        WheelItemData item = getItem(position);
        /*
        View root = inflater.inflate(R.layout.cycle_wheel_item, (ViewGroup)parent, false);
        FrameLayout flItem  = (FrameLayout) root.findViewById(R.id.dot_item);
        flItem.setBackground(item.dateColor);*/
        View root = inflater.inflate(R.layout.date_item, (ViewGroup) mParent, false);

        TextView tvDayOfWeek = (TextView) root.findViewById(R.id.tvDayOfWeek);
        TextView tvDayOfMonth = (TextView) root.findViewById(R.id.tvDayOfMonth);
        TextView tvDate = (TextView) root.findViewById(R.id.tvDate);
        TextView tvDateDetail = (TextView) root.findViewById(R.id.tvDateDetail);
        tvDateDetail.setText(Html.fromHtml(""));
        tvDayOfWeek.setTextColor(Color.GREEN);
        tvDayOfWeek.setText(format.format(item.date));
        tvDayOfMonth.setTextColor(Color.GREEN);
        tvDayOfMonth.setText("" + item.date.getDate());
        tvDate.setText(formatLong.format(item.date));
        View view = root.findViewById(R.id.fldot);
        root.findViewById(R.id.fldot).setBackground(item.dateColor);
        return root;
    }

    @Override
    public WheelItemData getItem(int position) {
        return data.get(position);
    }

    public static void SetAni(View child) {

        if (set != null) {
            //set.cancel();
            set.end();
            set.start();
            set.cancel();
        }
        //ViewWithAni = child;

        set = new AnimatorSet();
        View view = child.findViewById(R.id.fldot);
        ObjectAnimator viewSmallY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1.5f).setDuration(1000);
        viewSmallY.setRepeatCount(ValueAnimator.INFINITE);
        viewSmallY.setRepeatMode(ObjectAnimator.REVERSE);
        ObjectAnimator viewSmallX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1.5f).setDuration(1000);
        viewSmallX.setRepeatCount(ValueAnimator.INFINITE);
        viewSmallX.setRepeatMode(ObjectAnimator.REVERSE);
        set.play(viewSmallY).with(viewSmallX);
        set.start();
    }

    public static View SetViewLayout(View view, WheelItemData data) {
        TextView tvDayOfWeek = (TextView) view.findViewById(R.id.tvDayOfWeek);
        TextView tvDayOfMonth = (TextView) view.findViewById(R.id.tvDayOfMonth);
        TextView tvDate = (TextView) view.findViewById(R.id.tvDate);
        TextView tvDateDetail = (TextView) view.findViewById(R.id.tvDateDetail);
        //tvDateDetail.setText(Html.fromHtml(data.dateDetail));
        tvDayOfWeek.setTextColor(Color.GREEN);
        tvDayOfWeek.setText(format.format(data.date));
        tvDayOfMonth.setTextColor(Color.GREEN);
        tvDayOfMonth.setText("" + data.date.getDate());
        tvDate.setText(formatLong.format(data.date));
        return view;
    }
}
